<?php

namespace backend\controllers;

use Yii;
use backend\models\JobType;
use backend\actions\CreateAction;
use backend\actions\UpdateAction;
use backend\actions\IndexAction;
use backend\actions\DeleteAction;
use backend\actions\SortAction;
use backend\actions\ViewAction;
use yii\data\ActiveDataProvider;
use yii\helpers\Url;

/**
 * JobTypeController implements the CRUD actions for JobType model.
 */
class JobTypeController extends \yii\web\Controller
{
    public function actions()
    {
        return [
            'index'      => [
                'class' => IndexAction::className(),
                'data'  => function () {

                    $dataProvider = new ActiveDataProvider([
                        'query' => JobType::find(),
                    ]);

                    return [
                        'dataProvider' => $dataProvider,
                    ];

                }
            ],
            'job'        => [
                'class'    => IndexAction::className(),
                'viewFile' => 'index',
                'data'     => function () {

                    $dataProvider = new ActiveDataProvider([
                        'query' => JobType::find()->where(['type' => JobType::TYPE_JOB]),
                    ]);

                    return [
                        'url'          => Url::to(['job-type/job']),
                        'type'         => JobType::TYPE_JOB,
                        'dataProvider' => $dataProvider,
                    ];

                }
            ],
            'mission'    => [
                'class'    => IndexAction::className(),
                'viewFile' => 'index',
                'data'     => function () {

                    $dataProvider = new ActiveDataProvider([
                        'query' => JobType::find()->where(['type' => JobType::TYPE_MISSION]),
                    ]);

                    return [
                        'url'          => Url::to(['job-type/mission']),
                        'type'         => JobType::TYPE_MISSION,
                        'dataProvider' => $dataProvider,
                    ];

                }
            ],
            'create'     => [
                'class'           => CreateAction::className(),
                'modelClass'      => JobType::className(),
                'data'            => [
                    'url' => Yii::$app->request->get('type') == JobType::TYPE_JOB ? Url::to(['job-type/job']) : Url::to(['job-type/mission'])
                ],
                'successRedirect' => Yii::$app->request->get('type') == JobType::TYPE_JOB ? Url::to(['job-type/job']) : Url::to(['job-type/mission']),
            ],
            'update'     => [
                'class'      => UpdateAction::className(),
                'data'       => [
                    'url' => Yii::$app->request->get('type') == JobType::TYPE_JOB ? Url::to(['job-type/job']) : Url::to(['job-type/mission'])
                ],
                'modelClass' => JobType::className(),
            ],
            'delete'     => [
                'class'      => DeleteAction::className(),
                'modelClass' => JobType::className(),
            ],
            'sort'       => [
                'class'      => SortAction::className(),
                'modelClass' => JobType::className(),
            ],
            'view-layer' => [
                'class'      => ViewAction::className(),
                'modelClass' => JobType::className(),
            ],
        ];
    }

}
